<?php
class Pageley_Gateway_Database_Condition_EqualsSqlDecorator extends Pageley_Gateway_Database_Condition_SingleSqlDecorator {
	
	public function __construct($decoratedCondition, $query) {
		parent::__construct($decoratedCondition, $query);
	}
	
	protected function createSql() {
		$sql = null;
		$type = $this->getQuery()->getType();
		$propertyName = $this->getDecoratedCondition()->getPropertyName();
		$attribute = $type->getAttribute($propertyName);
		if($attribute === null) {
			throw new Pageley_Gateway_Database_Exception("No such property '" . $propertyName . "' on type '" . $type->getFullName() . "'.");
		}
        if($this->getDecoratedCondition()->getValue() === null) {
            $sql = $this->getQuery()->getAlias($type) . ".\"" .
                $this->getColumnName($propertyName) .
                "\" IS NULL";
        } else {
            $sql = parent::createSql();
        }
        return $sql;
	}
}